<template>
    <div class="user">
        <commonUserinfo :userInfoData="{userItemIndex:itemIndex,userLeftHeight:userLeftHeight,$parent:$parent}">
            <div id="modifyPwd" class="user_main_right f_left text_center">
                <div class="user_right_tip">
                    温馨提示：为确保您的学习信息一致<br>首次登录请绑定本人手机号，更换手机请输入新的手机号
                </div>
                <div class="user_userInfo modify_pwd color666">
                    <form ref="form" :model="form">
                        <dl>
                            <dt class="f_left">手机号：</dt>
                            <dd class="f_left"><input v-model.trim="form.telephone" type="text"></dd>
                        </dl>
                        <dl>
                            <dt class="f_left">验证码：</dt>
                            <dd class="f_left">
                                <input v-model.trim="form.code" class="modify_code" type="text">
                                <input type="button" :value="verifyCode" :disabled="disabled" @click="getVerifyCode"
                                    class="modify_getCode_btn text_center">
                            </dd>
                        </dl>
                        <a class="modify_sure_btn" @click="modifyPwd(form)">保存</a>
                    </form>
                </div>
            </div>
        </commonUserinfo>
    </div>
</template>

<script>
    import commonUserinfo from '../../components/c_userinfo.vue'
    export default {
        name: "update_phone",
        data: function() {
            return {
                itemIndex: 6,
                userLeftHeight: '',
                verifyCode: "获取验证码",
                disabled: false,
                form: {
                    telephone: "",
                    code: "",
                    v_token: ""
                }
            }
        },
        mounted: function() {
        },
        methods: {
            getVerifyCode: function() {
                var that = this;
                this.common.post(this.api.getVerifyCodeChangeTelephone, {
                    telephone: this.form.telephone
                }, function(data) {
                    that.form.v_token = data.resultMap;
                    that.setInter();
                }, function(error) {
                    that.$message.error(error.resultMsg);
                });

            },
            setInter: function() {
                var that = this;
                var countDown = 60;
                clearInterval(timer);
                var timer = setInterval(function() {
                    countDown--;
                    that.verifyCode = "短信已发送（" + countDown + "）";
                    that.disabled = true;
                    if (countDown < 1) {
                        clearInterval(timer);
                        that.verifyCode = "获取短信验证码";
                        that.disabled = false;
                    }
                }, 1000);
            },
            modifyPwd: function() {
                var that = this;
                if (this.form.telephone.trim() == "") {
                    this.$message.error('请输入新手机号！');
                    return;
                }
                if (this.form.code.trim() == "") {
                    this.$message.error('请输入验证码！');
                    return;
                }
                this.common.post(this.api.changeTelephone, this.form, function(data) {
                    that.common.toPage("/user_info");
                }, function(error) {
                    that.$message.error(error.resultMsg);
                });
            }
        },
        components: {
            commonUserinfo
        }
    }
</script>

<style>

</style>
